Docly Developers
Knowledge base Bug Workaround available

Date and time values written from code show as empty in the editor

In shortWhen code writes a date and time as ISO text - with or without a time zone - saveFile and patchFile store it as UTC with a Z. A date and time field in the editor cannot show that value and appears empty. Store timestamps as plain text in a local format such as 05.12.2026 23:59:00, and convert in code.
Applies to SchemasDataAPI
  1. What you'll see

    A schema has a date and time field (Input with Type: "datetime-local"). Code fills it with docly.patchFile(doc, { ValidTo: "2026-12-05T23:59:00" }). The value is stored, the code can read it back, but when the document is opened in the editor the field is empty.

  2. What's actually happening

    Text that looks like an ISO date and time is turned into a date when the document is stored, and written back as UTC with a Z. Verified 2026-11-28 on a Docly server running Norwegian time: "2026-11-28T22:51:40" was stored as "2026-11-28T21:51:40Z", and "…Z" values were stored unchanged. The editor's date and time field (<input type="datetime-local">) only accepts values without a time zone, so every such field showed as empty. Saving the form from the editor at that point can write the empty value back.

    There is a second trap: code that reads the value back gets the UTC text. If it parses the digits as local time, every read moves the time by the UTC offset, and every write-back moves it again.

  3. What to do

    Store timestamps as plain text in a local format that is not ISO, so Docly leaves it alone and the editor shows it as written. Use a text field (Type: "") with a placeholder that shows the format.

    // write: "05.12.2026 23:59:00" in local time
    docly.patchFile(doc, { ValidTo: formatLocal(validToMs) });
    
    // read: parse the local text back to a point in time
    var validTo = parseLocal(t.ValidTo);
    • Convert with the time zone of the users, not the server's. Format and parse in local time explicitly (for Norway: UTC+1, UTC+2 from the last Sunday in March to the last Sunday in October, both at 01:00 UTC).
    • Accept old values with a Z when you parse, so documents written before the change still read correctly.
    • Compare and sort with the parsed number, never with the text.

    Don't: write new Date(ms).toISOString() or "2026-12-05T23:59" into a field people will read in the editor.

Last reviewed 28 Nov 2026